#!/bin/bash

./stop.sh
sleep 0.5s

DEBUG_PORT=8055
JAR_FILE=sim-cert-paas.jar
APPLICATION_NAME=sim-cert-paas
SERVICE_NAME=cert-paas-server

JAVA_CMD=java
if [ -n "$JAVA_HOME" ]; then
    JAVA_CMD=$JAVA_HOME/bin/java
fi

# jvm args
JVM_HEAP_MIN_SIZE=212m
JVM_HEAP_MAX_SIZE=2g
JVM_META_MIN=64m
JVM_META_MAX=256m
JVM_DIRECT_SIZE=212m
JAVA_DEBUG_OPTS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=${DEBUG_PORT},server=y,suspend=n"
JAVA_OPTS="$JAVA_OPTS -server -Xms${JVM_HEAP_MIN_SIZE} -Xmx${JVM_HEAP_MAX_SIZE} -Xss256k -XX:MetaspaceSize=${JVM_META_MIN} -XX:MaxMetaspaceSize=${JVM_META_MAX} -XX:MaxDirectMemorySize=${JVM_DIRECT_SIZE} -XX:SurvivorRatio=6 -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses -XX:+HeapDumpOnOutOfMemoryError"
# end of jvm args


echo start $SERVICE_NAME...
#$JAVA_CMD  -javaagent:agent.jar -Dproject.name=Certificate_PAAS_test -Diast.server.mode=local  $JAVA_DEBUG_OPTS $JAVA_OPTS  -jar $JAR_FILE --spring.profiles.active=test > ./console.log 2>&1 < /dev/null &
$JAVA_CMD $JAVA_DEBUG_OPTS  $JAVA_OPTS -jar  $JAR_FILE --spring.profiles.active=test > ./console.log 2>&1 < /dev/null &


while [ -z "$pid" ]
do
    sleep 0.1s
    pid=`ps -ef | grep $APPLICATION_NAME | grep -v grep | awk '{print $2}'`
done
echo $SERVICE_NAME start ok!